jQuery().ready(
			function(){
jQuery("#list1").jqGrid({
							url : baserUrl+'policy/list?'+$('form').serialize(),
							height: '100%',
							datatype : "json",
							colNames : [ 'ID','安全网关1','安全网关2','安全网关3', '网关1', '网关2', '网关3','网关端口','网管地址','网管账号','IP地址段'],
							colModel : [{
								name : 'id',
								index : 'id',
								width : 75,
								editable:true,
								hidden:true,
								editrules:{required:false},
							},{
								name : 'safeGateway1',
								index : 'safeGateway1',
								width : 100,
								editable:true,
							
							},{
								name : 'safeGateway2',
								index : 'safeGateway2',
								width : 100,
								editable:true,
							
							},{
								name : 'safeGateway3',
								index : 'safeGateway3',
								width : 100,
								editable:true,
							
							},{
								name : 'gateway1',
								index : 'gateway1',
								width : 100,
								editable:true,
							},{
								name : 'gateway2',
								index : 'gateway2',
								width : 100,
								editable:true,
							},{
								name : 'gateway3',
								index : 'gateway3',
								width : 100,
								editable:true,
							},
							
							{
								name : 'gatewayPort',
								index : 'gatewayPort',
								width : 100,
								editable:true,
							}, {
								name : 'acsAddress',
								index : 'acsAddress',
								width : 75,
								editable:false,
								editrules:{required:true},
							},{
								name : 'acsAccount',
								index : 'acsAccount',
								width : 75,
								editable:false,
								editrules:{required:true},
							},{
								name : 'ipRange',
								index : 'ipRange',
								width : 75,
								editable:false,
								editrules:{required:true},
							}],
							rowNum : 20,//每页显示条数
							autowidth : true,
							rowList : [20, 50,100 ],
							pager : jQuery('#pager1'),
							sortname : 'id',
							viewrecords : true,//是否显示行数
							sortorder : "desc",
							multiselect: true,
							caption : "网关设置列表",
							cellsubmit: 'clientArray',
							editurl:baserUrl+'policy/save',
							jsonReader : {  
	    						root: "rows",   // json中代表实际模型数据的入口  
	    						page: "currentPage",   // json中代表当前页码的数据  
	    						total: "totalPage", // json中代表页码总数的数据  
	    						records: "total", // json中代表数据行总数的数据  
	    						repeatitems: false, // 如果设为false，则jqGrid在解析json时，会根据name来搜索对应的数据元素（即可以json中元素可以不按顺序）；而所使用的name是来自于colModel中的name设定。  
	    						cell: "cell",  
	    						id: "0",  
	    						userdata: "userdata",
    						},
    						    prmNames : {
							       
							    }  
						});
						jQuery("#list1").navGrid('#pager1',{edit:false,add:false,del:true,search:false},
							{
								
						    },
						    {
						    	beforeSubmit : function(postdata, formid) 
						    	{
							    	$.each(postdata,function(key, value){
							    		postdata['guiPolicy.'+key] = value;
							    		delete postdata[key];
									});
		
					               	console.info(postdata);
							    	return [true,""]
								},
								afterShowForm: function($form) {
                         		 $form.closest('div.ui-jqdialog').center();
                      			},
                      			closeAfterAdd: true,
    						    closeAfterEdit: true
						    },
						    {
						    	reloadAfterSubmit:true,
						    	url:baserUrl+'policy/delete',
								afterShowForm: function($form) {
                         		 $form.closest('div.ui-jqdialog').center();
                      			}
						    },//del
						    {}
						    ).navButtonAdd('#pager1'
							,{
								caption:"", buttonicon:"ui-icon-search",   
								onClickButton: function(){searchevent();}, position:"first"  
						    }
							
						)
						.navButtonAdd('#pager1'
							,{
								caption:"", buttonicon:"ui-icon-pencil",   
								onClickButton: function(){editevent();}, position:"first"  
						    }
							
						).navButtonAdd('#pager1'
							,{
								caption:"", buttonicon:"ui-icon-plus",   
								onClickButton: function(){getDetail(baserUrl+"policy/detail");}, position:"first"  
						    }
							
						);
						
				/**jQuery("#list1").jqGrid('navGrid','#pager1',{  
       			 		searchfunc : searchevent,
    					});**/
    					
    					initdialog();
    					initaddDialog();
			});


function initdialog (){
	$( ".searchbar" ).dialog({
autoOpen: false,
height: 400,
width: 500,
modal: true,
buttons: {
"查询": function() {
queryDevice();
},
"取消": function() {
$( this ).dialog( "close" );
}
},
close: function() {

}
});
}

function initaddDialog (){
	$(".policyDetail").dialog({
	autoOpen: false,
	height: 550,
	width: 500,
	modal: true,
	buttons: {
	"确认": function() {
			submitData();
	},
	"取消": function() {
		$( ".policyDetail" ).dialog( "close" );
	}
},
close: function() {
},
beforeClose: function( event, ui ) {$( ".policyDetail" ).dialog( "option", "width", 500 );}
});
}

function reload(){
	$( ".policyDetail" ).dialog( "close" );
	$("#list1").trigger("reloadGrid");
}

function  queryDevice(){
	$("#list1").setGridParam({url:baserUrl+'policy/list?'+$('form').serialize()});
    $("#list1").trigger("reloadGrid");
    return false;
}

var  editevent = function(){
	var id = $("#list1").jqGrid('getGridParam','selrow');
    //根据id获取行数据,返回的是列表
    var rowDatas = $("#list1").jqGrid('getRowData', id);
    //取到选中行某一字段的值，其中name为colModel中定义的字段名
    var rowId = rowDatas["id"];
	getDetail(baserUrl+'policy/detail?id='+rowId);
}

var  searchevent = function(){
	$( ".searchbar" ).dialog( "open" );
}
var  getDetail= function(url){
	$('.policyDetail').load(url);
	$( ".policyDetail" ).dialog( "open" );
}


